package adata;

import java.util.LinkedList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.RowSet;

import model.ApplicationModel;


import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


import db.DbException;
import forms.ApplicantForm;
import forms.Degree;

public class DegreeUniversityPageAction extends Action{
	
	public ActionForward execute(ActionMapping mapping, ActionForm form, 
		    HttpServletRequest request, HttpServletResponse response) 
		    throws DbException{
	
		
		
		RowSet crsMajors = ApplicationModel.getAllMajors();
		request.setAttribute("crsMajors", crsMajors);
		
		
		
		List<Degree> theDegreeArray;
		if (request.getSession().getAttribute("TheSessionDegreeArray") != null)
		{
			// retrieve list from session attribute if it exists
			theDegreeArray = (LinkedList<Degree>) request.getSession().getAttribute("TheSessionDegreeArray");
		}
		else
		{
			// create the list otherwise
			theDegreeArray = new LinkedList<Degree>();
		}
			
		String currentUniversityName = request.getParameter("universityName");
		
		//theDegreeArray.add (new Degree());
		Integer currentCount = (Integer)(request.getSession().getAttribute("SessionCounter"));
		theDegreeArray.get(currentCount).setUniversity(currentUniversityName.toString().replace('_', ' '));
		request.getSession().setAttribute ("TheSessionDegreeArray", theDegreeArray);
		
		
		
		return mapping.findForward("success");
		
	}
}
